package com.xnck.demo.flowabledemo.behavior;

import org.flowable.bpmn.model.ExclusiveGateway;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior;

public class ExtExclusiveGatewayActivityBehavior extends ExclusiveGatewayActivityBehavior {

    private static final long serialVersionUID = -2245991955225188129L;

    @Override
    public void leave(DelegateExecution execution) {
        ExclusiveGateway exclusiveGateway = (ExclusiveGateway) execution.getCurrentFlowElement();
        for (SequenceFlow sequenceFlow : exclusiveGateway.getOutgoingFlows()) {
            if ("testTrue".equals(sequenceFlow.getConditionExpression())) {
                sequenceFlow.setConditionExpression("${1==1}");
                System.out.println("经历过网关，设置条件为1==1");
            } else if ("testFalse".equals(sequenceFlow.getConditionExpression())) {
                sequenceFlow.setConditionExpression("${1!=1}");
                System.out.println("经历过网关，设置条件为1!=1");
            } else {
                System.out.println("经历过网关，保持原条件");
            }
        }
        super.leave(execution);
    }
}
